$(function(){
	$(".coll_body").eq(3).show();
	$(".coll_body").eq(3).children('a').eq(0).addClass("active");
	$(".Collapsing").eq(3).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(3).click(function(){
		$(".Collapsing").eq(3).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(0).toggleClass("active");
	})
//	获取租户列表
	$.ajax({
		type:"get",
		url:serverIP+"/user/util/GetCustomList",
		dataType:"json",
		async:false,
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
		success:function (data) {
			$.each(data.data, function(index,obj) {
				$('#cName').append('<option value='+obj.customerId+'>'+obj.name+'</option>');
			})
		}
	})
//	计算抄表总数
	$("#monoNum").text();

})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}
//	租户列表
	var pageSize = 15;
	var currentPage = 1;
	var cid="";
	var beginTime="";
	var finishTime="";
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/dayReve/list",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {page:currentPage},
				success:function (data) {
					if(data.code==0){
						let result=data.data.list.result;
						var strVar = "";
						SmonoNum=0;
						SmonoReve=0;
						ScolorNum=0;
						ScolorReve=0;
						Ssum=0;
						result.map(function(u,index){
							SmonoNum+=u.monoNum;
							SmonoReve+=u.monoReve;
							ScolorNum+=u.colorNum;
							ScolorReve+=u.colorReve;
							Ssum+=u.sum;
							strVar += "              <tr>";
						    strVar += "                <td>"+ ++index +"<\/td>\n";
						    strVar += "                <td>"+u.cName+"<\/td>\n";
						    strVar += "                <td>"+u.monoNum+"<\/td>\n";
						    strVar += "                <td>"+u.monoReve+"<\/td>\n";
						    strVar += "                <td>"+u.colorNum+"<\/td>\n";
						    strVar += "                <td>"+u.colorReve+"<\/td>\n";
						    strVar += "                <td>"+u.sum+"<\/td>\n";
						    strVar += "              <\/tr>";
						})
						$('#monoNum').text(SmonoNum);
						$('#monoReve').text(SmonoReve);
						$('#colorNum').text(ScolorNum);
						$('#colorReve').text(ScolorReve);
						$('#sum').text(Ssum);
						$('.print-tbody').html(strVar);
					//分页
						$("#page").paging({
							pageNo: data.data.list.curPage,
							totalPage: data.data.list.totalPage,
							totalSize: data.data.list.totalRow,
							callback: function(currentPage) {
								ajaxTest(currentPage); 
							}
						});
					}else{
						alert(data.msg);
					}/*if-End*/
				}
		})
	}
$('#selectOk').click(function(){
	$('#page').hide();
	$('.print-table').find('th span').hide();
	var beginTime=$('#beginTime').val();
	var finishTime=$('#finishTime').val();
	var cid=$('#cName').val();
	$.ajax({
		type:"post",
		url:serverIP+"/user/dayReve/list",
		dataType:"json",
		xhrFields: {
            withCredentials: true    // 设置sessionId相同
        },
        data: {cId:cid,dateBegin:beginTime,dateEnd:finishTime},
		success:function (data) {
			if(data.code==0){
				let result=data.data.list.result;
				var strVar = "";
				result.map(function(u,index){
					strVar += "              <tr>";
				    strVar += "                <td>"+ ++index +"<\/td>";
				    strVar += "                <td>"+u.cName+"<\/td>";
				    strVar += "                <td>"+u.monoNum+"<\/td>";
				    strVar += "                <td>"+u.monoReve+"<\/td>";
				    strVar += "                <td>"+u.colorNum+"<\/td>";
				    strVar += "                <td>"+u.colorReve+"<\/td>";
				    strVar += "                <td>"+u.sum+"<\/td>";
				    strVar += "              <\/tr>";
				})
				$('.print-tbody').html(strVar);
			}
		}
	})
})
//时间戳转换
$('#beginTime').each(function() {
	var a = new Calendar({
		targetCls: $(this),
		type: 'yyyy-mm-dd',
		wday: 2
	})
});
$('#finishTime').each(function() {
	var a = new Calendar({
		targetCls: $(this),
		type: 'yyyy-mm-dd',
		wday: 2
	})
});
